package com.fingard.dsp.bank.reqrespobj.batchbill;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.batchbill.detail.RetAtsBatOpenBillSubmitQryDetail;
import com.fingard.xml.XmlTextWriter;

/**
 * Created by F on 2019/10/21.
 */
public class RetAtsBatOpenBillSubmitQry extends RetAtsBase {
    /**
     * 执行状态码
     */
    public String respCode ="";
    /**
     * 执行信息
     */
    public String respInfo ="";
    /**
     * 协议号
     */
    public String protocolNo ="";
    /**
     * 请求唯一流水号
     */
    public String reqSeqID ="";
    /**
     * 交易状态码
     */
    public String transState ="";
    /**
     * 交易信息码
     */
    public String payInfoCode ="";

    public RetAtsBatOpenBillSubmitQry(ReqRespHeader p_header) {
        retHeader = p_header;
        retXmlWriter = new XmlTextWriter();
    }


    public void writeRetDetail(RetAtsBatOpenBillSubmitQryDetail detail) throws Exception {
        if (!hasWrittenBefore) {
            writeBeforeDetail();
        }
        retXmlWriter.writeStartElement("DetailRecord");
        retXmlWriter.writeElementString("RespCode", detail.respCode);
        retXmlWriter.writeElementString("RespInfo", detail.respInfo);
        retXmlWriter.writeElementString("BillState", detail.billState);
        retXmlWriter.writeElementString("Result", detail.result);
        retXmlWriter.writeElementString("PayInfoCode", detail.payInfoCode);
        retXmlWriter.writeElementString("BillNo", detail.billNo);
        retXmlWriter.writeElementString("PostScript", detail.postScript);
        retXmlWriter.writeEndElement();
    }

    private boolean hasWrittenBefore = false;
    public void writeBeforeDetail() throws Exception {
        if (hasWrittenBefore) {
            throw new Exception("writeBeforeDetail已被调用过");
        }
        writeStart();
        retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
        retXmlWriter.writeElementString("RespCode", respCode);
        retXmlWriter.writeElementString("RespInfo", respInfo);
        retXmlWriter.writeElementString("ProtocolNo", protocolNo);
        retXmlWriter.writeElementString("TransState", transState);
        retXmlWriter.writeElementString("PayInfoCode", payInfoCode);
        hasWrittenBefore = true;
    }

    public void writeAfterDetail() throws Exception {
        if (!hasWrittenBefore) {
            writeBeforeDetail();
        }
        writeEnd();// 写结束
    }
}
